import md5 from './md5.js'

function ksort(o) {
    let sorted = {}
    const keys = Object.keys(o || {})
    keys.sort()
    keys.forEach((key) => {
        sorted[key] = o[key]
    })
    return sorted
}

function md5_sign(params) {
    let data = params
    let str = ''
    data = ksort(data)
    for (let i in data) {
        if (i !== '') {
            str += i + data[i]
        }
    }
    data.req_time = Math.round(new Date()/1000)
    data.sign = md5.md5("zhuyuanbang" + str + data.req_time)
    return data
  
}



export default { md5_sign }
